package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.entity.Tag;
import com.sangeng.service.ITagService;
import com.sangeng.vo.TagVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/tag")
public class TagController {
    @Autowired
    private ITagService tagService;

    @GetMapping("/list")
    public ResponseResult list(){
        return ResponseResult.okResult(tagService.list());
    }

    @PostMapping
    public ResponseResult add(@RequestBody Tag tag){
        tagService.save(tag);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult remove(@PathVariable(name = "id") Long id){
        tagService.removeById(id);
        return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    public ResponseResult getInfo(@PathVariable(name = "id") Long id){
        return ResponseResult.okResult(tagService.getById(id));
    }

    @PutMapping
    public ResponseResult edit(@RequestBody Tag tag){
        tagService.updateById(tag);
        return ResponseResult.okResult();
    }

    @GetMapping("/listAllTag")
    public ResponseResult listAllTag(){
        List<TagVo> list = tagService.listAllTag();
        return ResponseResult.okResult(list);
    }
}